package com.tianya.portal.blog.service.impl;

import com.tianya.common.web.utils.StringUtils;
import com.tianya.portal.blog.domain.BlogBookArchives;
import com.tianya.portal.blog.mapper.BlogBookArchivesMapper;
import com.tianya.portal.blog.service.IBlogBookArchivesService;
import com.tianya.portal.system.domain.SysFile;
import com.tianya.portal.system.mapper.SysFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文学档案 服务层实现
 *
 * @author tianya
 * @date 2024-06-10
 */
@Service
public class BlogBookArchivesServiceImpl implements IBlogBookArchivesService {
    @Autowired
    private BlogBookArchivesMapper blogBookArchivesMapper;

    @Autowired
    private SysFileMapper sysFileMapper;

    /**
     * 查询文学档案信息
     *
     * @param id 文学档案ID
     * @return 文学档案信息
     */
    @Override
    public BlogBookArchives selectBlogBookArchivesById(String id) {
        BlogBookArchives bookArchives = blogBookArchivesMapper.selectBlogBookArchivesById(id);
        if (StringUtils.isNotEmpty(bookArchives.getImageId())) {
            SysFile sysFile = sysFileMapper.selectSysFileById(bookArchives.getImageId());
            bookArchives.setSysFile(sysFile);
        }
        return bookArchives;
    }

    /**
     * 查询文学档案列表
     *
     * @param blogBookArchives 文学档案信息
     * @return 文学档案集合
     */
    @Override
    public List<BlogBookArchives> selectBlogBookArchivesList(BlogBookArchives blogBookArchives) {
        List<BlogBookArchives> bookArchivesList = blogBookArchivesMapper.selectBlogBookArchivesList(blogBookArchives);
        for (BlogBookArchives bookArchives : bookArchivesList) {
            if (StringUtils.isNotEmpty(bookArchives.getImageId())) {
                SysFile sysFile = sysFileMapper.selectSysFileById(bookArchives.getImageId());
                bookArchives.setSysFile(sysFile);
            }
        }
        return bookArchivesList;
    }
}
